Java 8 Principal - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Principal class.

This code example shows how to use the following methods:getName
         principal = ctx.getCallerPrincipal();
      } catch (IllegalStateException ex) {
         return "NO PRINCIPAL"; 
      } 
 
      return principal.getName();
 
   } 
} 
 
 
7
CodeRank
This code example shows how to use the following methods:getName
    public void init() throws Exception { 
        // on Stateful bean is permitted to call getCallerPrincipal on @PostConstruct 
        ITestResultsSingleton results = this.getSingleton();
         
        Principal princ = sessContext.getCallerPrincipal();
        results.setSfsb("postconstruct", princ.getName() + "start");
        log.info(SFSBLifecycleCallback.class.getSimpleName() + " @PostConstruct called");
    } 
     
     @PreDestroy 
    public void tearDown() throws Exception { 
        // on Stateful bean is permitted to call getCallerPrincipal on @PreDestroy 
        ITestResultsSingleton results = this.getSingleton();
         
        Principal princ = sessContext.getCallerPrincipal();
        results.setSfsb("predestroy", princ.getName() + "stop");
        log.info(SFSBLifecycleCallback.class.getSimpleName() + " @PreDestroy called");
    } 
     
    public String get() {
7
CodeRank
This code example shows how to use the following methods:getName
        this.credential = null;
    } 
 
    public AccountImpl(final Principal principal) {
        this.principal = principal;
        this.name = principal.getName();
        this.credential = null;
    } 
    public AccountImpl(final Principal principal, Set<String> roles, final Object credential) {
        this.principal = principal;
        this.credential = credential;
        this.name = principal.getName();
        this.roles.addAll(roles);
    } 
 
    void setRoles(final Set<String> roles) {
        this.roles.clear();
        roles.addAll(roles);
    } 
 
7
CodeRank
This code example shows how to use the following methods:getName
    } 
 
    public void testCreateUserWithItermediatePath() throws NotExecutableException { 
        try { 
            Principal p = getTestPrincipal();
            User u = uMgr.createUser(p.getName(), buildPassword(p), p, "/any/intermediate/path");
            save(uSession);
 
            fail("A non-UserAdmin should not be allowed to create a new User."); 
 
            // clean-up: let superuser remove the user created by fault. 
            userMgr.getAuthorizable(u.getID()).remove();
        } catch (AuthorizableExistsException e) {
            // should never get here. 
            fail(e.getMessage());
        } catch (RepositoryException e) {
            // success 
        } 
    } 
 
6
CodeRank
This code example shows how to use the following methods:getName
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.SECOND, 10);// Add 25 seconds
 
            logger.trace("Will expire from cache in 10 seconds, principal = " + principal);
 
            cacheExpiry.register(securityDomain, calendar.getTime(), principal);
            // Additional expiry of simple principal 
            cacheExpiry.register(securityDomain, calendar.getTime(), new SimplePrincipal(principal.getName()));
        } catch (NamingException e) {
            throw new RuntimeException(e);
        } 
 
        return false; 
    } 
 
    /** 
     * @see org.picketlink.identity.federation.bindings.tomcat.SubjectSecurityInteraction#get() 
     */ 
    public Subject get() {
        try { 
6
CodeRank
This code example shows how to use the following methods:getName
            public Principal getUserPrincipal() {
                return p;
            } 
 
            public boolean isUserInRole(String role) {
                return role.equals(p.getName()) || ("user".equals(role) && "admin".equals(p.getName()));
            } 
 
            public boolean isSecure() { 
                return false; 
            } 
 
            public String getAuthenticationScheme() {
                return ""; 
            } 
        } 
    } 
 
    @Path("/") 
    @PermitAll 
6
CodeRank
This code example shows how to use the following methods:getName
    } 
 
    /* ------------------------------------------------------------ */ 
    public void logout(Principal user)
    { 
        remove(user.getName());
    } 
     
    /* ------------------------------------------------------------ */ 
    /** (re)Connect to database with parameters setup by loadConfig() 
     */ 
    public void connectDatabase() 
    { 
        try  
        { 
            _con = DriverManager.getConnection(_url, _userName, _password);
        } 
        catch(SQLException e)
        { 
            log.warn("UserRealm " + getName()
6
CodeRank
This code example shows how to use the following methods:getName
        } 
    } 
     
    public void testCreateUserPrincipal() throws IOException 
    { 
        _database.createPrincipal(PRINCIPAL, PASSWORD.toCharArray());
        Principal newPrincipal = _database.getUser(PRINCIPAL_USERNAME);
        assertNotNull(newPrincipal);
        assertEquals(PRINCIPAL.getName(), newPrincipal.getName());
    } 
     
    public void testVerifyPassword() throws IOException, AccountNotFoundException 
    { 
        testCreateUserPrincipal(); 
        //assertFalse(_pwdDB.verifyPassword(_username, null)); 
        assertFalse(_database.verifyPassword(PRINCIPAL_USERNAME, new char[]{}));
        assertFalse(_database.verifyPassword(PRINCIPAL_USERNAME, (PASSWORD+"z").toCharArray()));
        assertTrue(_database.verifyPassword(PRINCIPAL_USERNAME, PASSWORD.toCharArray()));
         
        try 

6
CodeRank
This code example shows how to use the following methods:getName
        // Get authentication type 
        authType = req.getAuthType();
 
        writer.println(PAGE_HEADER);
        writer.println("<h1>" + "Successfully called Secured Servlet " + "</h1>");
        writer.println("<p>" + "Principal  : " + principal.getName() + "</p>");
        writer.println("<p>" + "Remote User : " + remoteUser + "</p>");
        writer.println("<p>" + "Authentication Type : " + authType + "</p>");
        writer.println(PAGE_FOOTER);
        writer.close();
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:getName
            authType = req.getAuthType();
     
            writer.println(PAGE_HEADER);
            writer.println("<h1>" + "Successfully called Secured Servlet "
                    + "</h1>"); 
            writer.println("<p>" + "Principal  : " + principal.getName() + "</p>");
            writer.println("<p>" + "Remote User : " + remoteUser + "</p>");
            writer.println("<p>" + "Authentication Type : " + authType + "</p>");
            writer.println(PAGE_FOOTER);
            writer.close();
        } 
    } 
 
} 
6
CodeRank

Related Java 8 Principal Questions & Answers:

See Code Examples for Java 8 Principal Methods: