Made the principal for jaas sample serializable
This commit is contained in:
parent
6983b166d8
commit
9e5d35235c
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package samples.jaas;
|
package samples.jaas;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -71,18 +72,25 @@ public class UsernameEqualsPasswordLoginModule implements LoginModule {
|
||||||
throw new LoginException("username is not equal to password");
|
throw new LoginException("username is not equal to password");
|
||||||
}
|
}
|
||||||
|
|
||||||
subject.getPrincipals().add(new Principal() {
|
subject.getPrincipals().add(new UsernamePrincipal(username));
|
||||||
public String getName() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
public String toString() {
|
|
||||||
return "Principal [name="+getName()+"]";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean logout() throws LoginException {
|
public boolean logout() throws LoginException {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class UsernamePrincipal implements Principal, Serializable {
|
||||||
|
private final String username;
|
||||||
|
public UsernamePrincipal(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
public String toString() {
|
||||||
|
return "Principal [name="+getName()+"]";
|
||||||
|
}
|
||||||
|
private static final long serialVersionUID = 8049681145355488137L;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue