Revision 1199 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/identitymanagement/UnauthorizedException.java

View differences:

UnauthorizedException.java
1

  
2 1
package org.gvsig.tools.identitymanagement;
3 2

  
4 3
import org.apache.commons.lang3.StringUtils;
5 4
import org.gvsig.tools.ToolsLocator;
6 5

  
6
public class UnauthorizedException extends RuntimeException {
7 7

  
8
public class UnauthorizedException extends RuntimeException {
9
    
10 8
    private SimpleIdentity identity;
11 9
    private String actionName;
12 10
    private Object resource;
13 11
    private String resourceName;
14
    
12

  
15 13
    public UnauthorizedException(SimpleIdentity identity, String actionName, Object resource, String resourceName) {
16 14
        this.actionName = actionName;
17 15
        this.identity = identity;
18 16
        this.resource = resource;
19 17
        this.resourceName = resourceName;
20
        if( this.identity == null ) {
18
        if (this.identity == null) {
21 19
            SimpleIdentityManager identityManager = ToolsLocator.getIdentityManager();
22 20
            this.identity = identityManager.getCurrentIdentity();
23 21
        }
24 22
    }
25 23

  
26 24
    public UnauthorizedException(String actionName, Object resource, String resourceName) {
27
        this(null,actionName,resource,resourceName);
25
        this(null, actionName, resource, resourceName);
28 26
    }
29 27

  
30 28
    @Override
......
35 33
        builder.append("' is not authorized to '");
36 34
        builder.append(this.actionName);
37 35
        builder.append("'");
38
        if( !StringUtils.isBlank(this.resourceName) ) {
36
        if (!StringUtils.isBlank(this.resourceName)) {
39 37
            builder.append(" to resource '");
40 38
            builder.append(this.resourceName);
41 39
            builder.append("'");
42 40
        }
43
        if( this.resource!=null ) {
41
        if (this.resource != null) {
44 42
            String s = null;
45 43
            try {
46 44
                s = resource.toString();
47
            } catch(Throwable th) {
45
            } catch (Throwable th) {
48 46
                // Do nothing.
49 47
            }
50
            if( s != null ) {
48
            if (s != null) {
51 49
                builder.append(" (");
52 50
                builder.append(s);
53 51
                builder.append(" )");
......
55 53
        }
56 54
        return builder.toString();
57 55
    }
58
    
56

  
57
    public SimpleIdentity getIdentity() {
58
        return identity;
59
    }
60

  
61
    public String getActionName() {
62
        return actionName;
63
    }
64

  
65
    public Object getResource() {
66
        return resource;
67
    }
68

  
69
    public String getResourceAsString() {
70
        String s = null;
71
        try {
72
            s = resource.toString();
73
        } catch (Throwable th) {
74
            // Do nothing.
75
        }
76
        return s;
77
    }
78

  
79
    public String getResourceName() {
80
        return resourceName;
81
    }
82

  
59 83
}

Also available in: Unified diff