]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.core/src/org/argeo/security/NodeAuthenticationToken.java
Fix: LDIF parser manages last entry properly.
[lgpl/argeo-commons.git] / org.argeo.security.core / src / org / argeo / security / NodeAuthenticationToken.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security;
17
18 import java.util.Collection;
19
20 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
21 import org.springframework.security.core.GrantedAuthority;
22
23 /** Credentials required for the authentication to a node. */
24 public class NodeAuthenticationToken extends
25 UsernamePasswordAuthenticationToken {
26 private static final long serialVersionUID = 1955222132884795213L;
27 private final String url;
28
29 /** Non authenticated local constructor */
30 public NodeAuthenticationToken(Object principal, Object credentials) {
31 super(principal, credentials);
32 this.url = null;
33 }
34
35 /** Non authenticated remote constructor */
36 public NodeAuthenticationToken(Object principal, Object credentials,
37 String url) {
38 super(principal, credentials);
39 this.url = url;
40 }
41
42 /** Authenticated constructor */
43 public NodeAuthenticationToken(NodeAuthenticationToken sat,
44 Collection<? extends GrantedAuthority> authorities) {
45 super(sat.getPrincipal(), sat.getCredentials(), authorities);
46 this.url = sat.getUrl();
47 }
48
49 public String getUrl() {
50 return url;
51 }
52
53 public Boolean isRemote() {
54 return url != null;
55 }
56
57 public String toString() {
58 String username = getName();
59 StringBuilder buf = new StringBuilder("groups=");
60 for (GrantedAuthority ga : getAuthorities()) {
61 if (!ga.getAuthority().equals(username)) {
62 buf.append(ga.getAuthority());
63 buf.append(',');
64 }
65 }
66 buf.deleteCharAt(buf.length() - 1);
67 return "uid=" + getName() + " " + buf.toString();
68 }
69 }