Package org.geoserver.security.impl

Examples of org.geoserver.security.impl.GeoServerUser


    }

    @Before
    public void setUpAuth() {
        GeoServerUser bob = GeoServerUser.createDefaultAdmin();
        //GroupAdminProperty.set(bob.getProperties(), new String[]{"users"});
        Authentication auth = new UsernamePasswordAuthenticationToken(
            bob, bob.getPassword(), Collections.singletonList(GeoServerRole.GROUP_ADMIN_ROLE));
        SecurityContextHolder.getContext().setAuthentication(auth);
    }
View Full Code Here


        }

        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        Object principal = auth.getPrincipal();
        if (principal instanceof GeoServerUser) {
            GeoServerUser user = (GeoServerUser) principal;
            obj.put("user", user.getUsername());
        }

        return obj;
    }
View Full Code Here

   
  }
 
  @Test
  public void testUserDetails() throws MalformedURLException {
    final UserDetails ud = new GeoServerUser("fred");
    SecurityContext context = new SecurityContext() {

      @Override
      public Authentication getAuthentication() {
        Authentication auth = new UsernamePasswordAuthenticationToken(ud,"barney");
View Full Code Here

*/
public class FakeMapper extends AbstractAuthenticationKeyMapper {

    @Override
    public GeoServerUser getUser(String key) throws IOException {
        return new GeoServerUser("fakeuser");
    }
View Full Code Here

        MockFilterChain chain = new MockFilterChain();
        getProxy().doFilter(request, response, chain);
        assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getErrorCode());

        // test success
        GeoServerUser user= (GeoServerUser) getSecurityManager().loadUserGroupService("ug1").loadUserByUsername(testUserName);
        String authKey=user.getProperties().getProperty(mapper.getUserPropertyName());
        assertNotNull(authKey);
       
               
        request = createRequest("/foo/bar");
        response = new MockHttpServletResponse();
View Full Code Here

    @Test
    public void testWebServiceAutheKeyMapper() throws Exception {
        GeoServerUserGroupService ugservice = createUserGroupService("testWebServiceAuthKey");
        GeoServerUserGroupStore ugstore = ugservice.createStore();
        GeoServerUser u1 = ugstore.createUserObject("user1", "passwd1", true);
        ugstore.addUser(u1);
        GeoServerUser u2 = ugstore.createUserObject("user2", "passwd2", true);
        ugstore.addUser(u2);
        ugstore.store();
       
        WebServiceAuthenticationKeyMapper propMapper =
                GeoServerExtensions.extensions(WebServiceAuthenticationKeyMapper.class).iterator().next();
        propMapper.setUserGroupServiceName("testWebServiceAuthKey");
        propMapper.setSecurityManager(getSecurityManager());
        propMapper.setWebServiceUrl("http://service/{key}");
        propMapper.setHttpClient(new TestHttpClient("testkey", "user1"));
        GeoServerUser user = propMapper.getUser("testkey");
        assertNotNull(user);
        assertEquals(user.getUsername(), "user1");
        boolean error = false;
        try {
            user = propMapper.getUser("wrongkey");
        } catch(UsernameNotFoundException e) {
            error = true;
View Full Code Here

   
    @Test
    public void testWebServiceAutheKeyMapperSearchUser() throws Exception {
        GeoServerUserGroupService ugservice = createUserGroupService("testWebServiceAuthKey2");
        GeoServerUserGroupStore ugstore = ugservice.createStore();
        GeoServerUser u1 = ugstore.createUserObject("user1", "passwd1", true);
        ugstore.addUser(u1);
        GeoServerUser u2 = ugstore.createUserObject("user2", "passwd2", true);
        ugstore.addUser(u2);
        ugstore.store();
       
        WebServiceAuthenticationKeyMapper propMapper =
                GeoServerExtensions.extensions(WebServiceAuthenticationKeyMapper.class).iterator().next();
        propMapper.setUserGroupServiceName("testWebServiceAuthKey2");
        propMapper.setSecurityManager(getSecurityManager());
        propMapper.setWebServiceUrl("http://service/{key}");
        propMapper.setSearchUser("^.*?\"user\"\\s*:\\s*\"([^\"]+)\".*$");
        propMapper.setHttpClient(new TestHttpClient("testkey", "{\n    \"user\": \"user1\", \"detail\": \"mydetail\"\n   }"));
        GeoServerUser user = propMapper.getUser("testkey");
        assertNotNull(user);
        assertEquals(user.getUsername(), "user1");
       
        propMapper.setSearchUser("^.*?<username>(.*?)</username>.*$");
        propMapper.setHttpClient(new TestHttpClient("testkey", "<root>\n<userdetail>\n<username>user1</username>\n</userdetail>\n</root>"));
        user = propMapper.getUser("testkey");
        assertNotNull(user);
        assertEquals(user.getUsername(), "user1");
       
       
        boolean error = false;
        try {
            user = propMapper.getUser("wrongkey");
View Full Code Here

    @Test
    public void testAuthKeyMapperSynchronize() throws Exception {
       
        GeoServerUserGroupService ugservice = createUserGroupService("testAuthKey");
        GeoServerUserGroupStore ugstore = ugservice.createStore();
        GeoServerUser u1 = ugstore.createUserObject("user1", "passwd1", true);
        ugstore.addUser(u1);
        GeoServerUser u2 = ugstore.createUserObject("user2", "passwd2", true);
        ugstore.addUser(u2);
        ugstore.store();
       
        PropertyAuthenticationKeyMapper propMapper =
                GeoServerExtensions.extensions(PropertyAuthenticationKeyMapper.class).iterator().next();

        UserPropertyAuthenticationKeyMapper userpropMapper =
                GeoServerExtensions.extensions(UserPropertyAuthenticationKeyMapper.class).iterator().next();
       
        propMapper.setSecurityManager(getSecurityManager());
        propMapper.setUserGroupServiceName("testAuthKey");
       
        userpropMapper.setSecurityManager(getSecurityManager());
        userpropMapper.setUserGroupServiceName("testAuthKey");

        // File Property Mapper
        assertEquals(2,propMapper.synchronize());
               
        File authKeyFile = new File(getSecurityManager().getUserGroupRoot(),"testAuthKey");
        authKeyFile=new File(authKeyFile,"authkeys.properties");
        assertTrue(authKeyFile.exists());
       
        Properties props = new Properties();
        loadPropFile(authKeyFile, props);
        assertEquals(2, props.size());
       
        String user1KeyA=null,user2KeyA=null,user3KeyA=null,
                user1KeyB=null,user2KeyB=null,user3KeyB=null;
       
        for (Entry<Object, Object> entry : props.entrySet()) {
            if ("user1".equals(entry.getValue()))
                user1KeyA=(String) entry.getKey();
            if ("user2".equals(entry.getValue()))
                user2KeyA=(String) entry.getKey();
        }
        assertNotNull(user1KeyA);
        assertNotNull(user2KeyA);
       
        assertEquals(u1, propMapper.getUser(user1KeyA));
        assertEquals(u2, propMapper.getUser(user2KeyA));
        assertNull(propMapper.getUser("blblal"));
       
       
       
        // user property mapper
        assertEquals(2,userpropMapper.synchronize());
        u1 = (GeoServerUser) ugservice.loadUserByUsername("user1");
        user1KeyB=u1.getProperties().getProperty(userpropMapper.getUserPropertyName());
        u2 = (GeoServerUser) ugservice.loadUserByUsername("user2");
        user2KeyB=u2.getProperties().getProperty(userpropMapper.getUserPropertyName());
       
        assertEquals(u1, userpropMapper.getUser(user1KeyB));
        assertEquals(u2, userpropMapper.getUser(user2KeyB));
        assertNull(userpropMapper.getUser("blblal"));

        // modify user/group database
       
        ugstore = ugservice.createStore();
        GeoServerUser u3 = ugstore.createUserObject("user3", "passwd3", true);
        ugstore.addUser(u3);
        ugstore.removeUser(u1);       
        ugstore.store();
       
        assertEquals(1,propMapper.synchronize());
       
       
        props = new Properties();
        loadPropFile(authKeyFile, props);
        assertEquals(2, props.size());
       
       
        for (Entry<Object, Object> entry : props.entrySet()) {
            if ("user2".equals(entry.getValue()))
                assertEquals(user2KeyA,(String) entry.getKey());
            if ("user3".equals(entry.getValue()))
                user3KeyA=(String) entry.getKey();
        }
        assertNotNull(user3KeyA);
       
       
        assertNull(propMapper.getUser(user1KeyA));
        assertEquals(u2, propMapper.getUser(user2KeyA));
        assertEquals(u3,propMapper.getUser(user3KeyA));
       
       
       
        // user property mapper
        assertEquals(1,userpropMapper.synchronize());
        u2 = (GeoServerUser) ugservice.loadUserByUsername("user2");
        assertEquals(user2KeyB,u2.getProperties().getProperty(userpropMapper.getUserPropertyName()));
        u3 = (GeoServerUser) ugservice.loadUserByUsername("user3");
        user3KeyB=u3.getProperties().getProperty(userpropMapper.getUserPropertyName());
       
        assertNull( userpropMapper.getUser(user1KeyB));
        assertEquals(u2, userpropMapper.getUser(user2KeyB));
        assertEquals(u3, userpropMapper.getUser(user3KeyB));
       
View Full Code Here

        String userName = authKeyProps.getProperty(key);
        if (StringUtils.hasLength(userName)==false) {           
            LOGGER.warning("Cannot find user for auth key: "+key);
            return null;
        }
        GeoServerUser theUser=null;
        try {
            theUser= (GeoServerUser)
                getUserGroupService().loadUserByUsername(userName);
        } catch (UsernameNotFoundException ex) {
            LOGGER.warning("Cannot find user: "+userName+" in user/group service: " +getUserGroupServiceName());
            return null;
        }
       
        if (theUser.isEnabled()==false) {                   
            LOGGER.info("Found user "+theUser.getUsername()+ " for key " + key +
                    ", but this user is disabled");
            return null;
        }
       
        return theUser;
View Full Code Here

            HttpServletResponse response,String authKeythrows IOException{

        if (authKey==null)
            return;
       
        GeoServerUser user = mapper.getUser(authKey);
        if (user==null) {
            return;
        }
       
        // no support for root login
        if (GeoServerUser.ROOT_USERNAME.equals(user.getUsername())) {
            LOGGER.warning("Authentication key login does accept the root user");
            return;
        }
       
        LOGGER.log(Level.FINE,"found user: = " + user.getUsername() + ", trying to authenticate");
                      
           
        Collection<GeoServerRole> roles= new ArrayList<GeoServerRole>();
        for (GrantedAuthority auth: user.getAuthorities()) {
            roles.add((GeoServerRole)auth);
        }       
        if (roles.contains(GeoServerRole.AUTHENTICATED_ROLE)==false)
            roles.add(GeoServerRole.AUTHENTICATED_ROLE);           
        KeyAuthenticationToken result = new KeyAuthenticationToken(authKey,  authKeyParamName,user, roles);
View Full Code Here

TOP

Related Classes of org.geoserver.security.impl.GeoServerUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.